package util;

import android.app.Instrumentation;
import android.content.pm.PackageManager;
import android.support.test.InstrumentationRegistry;
import android.support.test.uiautomator.Configurator;
import android.support.test.uiautomator.UiDevice;
import android.util.Log;

/**
 * Created by zhe.xiao on 2017/6/22.
 */

public class GetDevice {
    private static Instrumentation instrumentation;
    private static UiDevice device = null;

    public static UiDevice getDevice(){
        if(device == null) {
            Configurator c = Configurator.getInstance();
            c.setWaitForSelectorTimeout(20000);
            c.setActionAcknowledgmentTimeout(8000);
            instrumentation = InstrumentationRegistry.getInstrumentation();
            device = UiDevice.getInstance(instrumentation);
            Log.v("Device", "初始化一次");
            PackageManager pm = instrumentation.getTargetContext().getPackageManager();
            try {
                Log.i("com.qunat",pm.getApplicationBanner("com.Qunar").toString());
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }

        }
        return device;
    }
}
